from ecahrts_line import simple_line
from fastapi import FastAPI
import pandas as pd
from fastapi import Response
import numpy as np
from fastapi.middleware.cors import CORSMiddleware


app = FastAPI()


app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(simple_line.router)


@app.get("/")
async def root():
    return {"message": "Hello Bigger Applications!"}


@app.get('/testapi')
async def return_simple_data():
    '''
    这个是返回的一个随机数据
    '''
    num_part = 10
    simple_data = pd.DataFrame({'partname': [f"part_{i}" for i in range(num_part)],
                                'gmv': np.random.randint(low=10, high=30, size=num_part)})

    simple_data['nmv'] = simple_data['gmv'] - \
        np.random.randint(low=0, high=3, size=num_part)
    return Response(simple_data.to_json(orient='records'), media_type='application/json')


# uvicorn main:app --reload
